package com.iris.live.services.data.repositories;

import com.iris.live.services.data.models.TSalesAdminCheckModel;
import com.iris.live.services.data.models.TSalesConsultantCheckModel;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * 销售行政核检持久层
 * Created by wzy on 2017/5/19.
 */
public interface SalesAdminCheckRepository extends JpaRepository<TSalesAdminCheckModel, Integer>, JpaSpecificationExecutor<TSalesAdminCheckModel> {

    /**
     * 根据导入批次和车架号查找导入的销售行政数据
     * @param importBatch 导入批次
     * @param vin 车架号
     * @return 返回
     */
    @Query("select salesAdmin from TSalesAdminCheckModel salesAdmin where salesAdmin.importBatch = ?1 and salesAdmin.vin = ?2")
    TSalesAdminCheckModel findSalesAdminByImportBatchAndVin(String importBatch, String vin);

    /**
     * 根据导入车架号查找导入的销售行政数据
     * @param vin 车架号
     * @return 返回
     */
    @Query("select salesAdmin from TSalesAdminCheckModel salesAdmin where salesAdmin.vin = ?1")
    TSalesAdminCheckModel findSalesAdminByVin(String vin);

    /**
     * 根据导入批次和导入用户查找导入的销售行政数据
     * @param importBatch 导入批次
     * @param importUser 导入用户
     * @return 返回
     */
    @Query("select salesAdmin from TSalesAdminCheckModel salesAdmin where salesAdmin.importBatch = ?1 and salesAdmin.importUser = ?2")
    List<TSalesAdminCheckModel> findSalesAdminByImportBatchAndImportUser(String importBatch, String importUser);


    @Query("select a from TSalesAdminCheckModel a where a.permit = ?1 and a.importBatch = ?2")
    List<TSalesAdminCheckModel> findImportedSa(String permit, String batch);

    @Query("select a from TSalesConsultantCheckModel a where a.permit = ?1 and a.importBatch = ?2")
    List<TSalesConsultantCheckModel> findImportedSc(String permit, String batch);
}
